package system_code.CopyFile;

import java.io.*;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        //复制文件
        System.out.print("请输入您要复制的文件:");
        Scanner scanner = new Scanner(System.in);
        File srcFile = new File(scanner.next());
        if(!srcFile.isFile()){
            //不是文件
            System.out.println("您输入的文件名有误~");
            return;
        }
        System.out.println("您要复制的文件名是什么?");
        System.out.print("请输入:");
        File destFile = new File(scanner.next());
        if(!destFile.getParentFile().isDirectory()){
            System.out.println("输入的文件夹名有误~");
            return;
        }
        //开始复制
        try(InputStream inputStream = new FileInputStream(srcFile);
            OutputStream outputStream = new FileOutputStream(destFile)){
            while(true){
                int ret = inputStream.read();
                if(ret == -1){
                    break;
                }
                outputStream.write(ret);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
